package com.facebook.drawee.drawable;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;

public class ForwardingDrawable extends Drawable implements Drawable.Callback, DrawableParent, TransformAwareDrawable, TransformCallback {
    private Drawable mCurrentDelegate;
    private final DrawableProperties mDrawableProperties;
    private TransformCallback mTransformCallback;

    public ForwardingDrawable(Drawable drawable) {
        this.mDrawableProperties = new DrawableProperties();
        this.mCurrentDelegate = drawable;
        DrawableUtils.setCallbacks(this.mCurrentDelegate, ((Drawable.Callback) this), ((TransformCallback) this));
    }

    public final Drawable getDrawable() {
        return this.getCurrent();
    }

    public final Drawable setCurrent(Drawable drawable) {
        return this.setCurrentWithoutInvalidate(drawable);
    }

    public void getTransform(Matrix matrix) {
        this.getParentTransform(matrix);
    }

    public final void getRootBounds(RectF bounds) {
        if (this.mTransformCallback != null) {
            this.mTransformCallback.getRootBounds(bounds);
        } else {
            bounds.set(this.getBounds());
        }
    }

    public final void setTransformCallback(TransformCallback transformCallback) {
        this.mTransformCallback = transformCallback;
    }

    public final Drawable setCurrentWithoutInvalidate(Drawable newDelegate) {
        Drawable previousDelegate = this.mCurrentDelegate;
        DrawableUtils.setCallbacks(previousDelegate, null, null);
        DrawableUtils.setCallbacks(newDelegate, null, null);
        DrawableUtils.setDrawableProperties(newDelegate, this.mDrawableProperties);
        if (previousDelegate != null && newDelegate != null && newDelegate != previousDelegate) {
            newDelegate.setBounds(previousDelegate.getBounds());
            newDelegate.setChangingConfigurations(previousDelegate.getChangingConfigurations());
            newDelegate.setLevel(previousDelegate.getLevel());
            newDelegate.setVisible(previousDelegate.isVisible(), false);
            newDelegate.setState(previousDelegate.getState());
        }

        DrawableUtils.setCallbacks(newDelegate, this, this);
        this.mCurrentDelegate = newDelegate;
        this.invalidateSelf();
        return previousDelegate;
    }

    protected final void getParentTransform(Matrix matrix) {
        if (this.mTransformCallback != null) {
            this.mTransformCallback.getTransform(matrix);
        } else {
            matrix.reset();
        }
    }

    public void draw(Canvas canvas) {
        this.mCurrentDelegate.draw(canvas);
    }

    public Drawable getCurrent() {
        return this.mCurrentDelegate;
    }

    public int getIntrinsicHeight() {
        return this.mCurrentDelegate.getIntrinsicHeight();
    }

    public int getIntrinsicWidth() {
        return this.mCurrentDelegate.getIntrinsicWidth();
    }

    public int getOpacity() {
        return this.mCurrentDelegate.getOpacity();
    }

    public boolean getPadding(Rect padding) {
        return this.mCurrentDelegate.getPadding(padding);
    }

    public void invalidateDrawable(Drawable who) {
        this.invalidateSelf();
    }

    public boolean isStateful() {
        return this.mCurrentDelegate.isStateful();
    }

    public Drawable mutate() {
        this.mCurrentDelegate.mutate();
        return this;
    }

    protected void onBoundsChange(Rect arg2) {
        this.mCurrentDelegate.setBounds(arg2);
    }

    protected boolean onLevelChange(int arg2) {
        return this.mCurrentDelegate.setLevel(arg2);
    }

    protected boolean onStateChange(int[] arg2) {
        return this.mCurrentDelegate.setState(arg2);
    }

    public void scheduleDrawable(Drawable drawable, Runnable runnable, long arg4) {
        this.scheduleSelf(runnable, arg4);
    }

    public void setAlpha(int alpha) {
        this.mDrawableProperties.alpha = alpha;
        this.mCurrentDelegate.setAlpha(alpha);
    }

    public void setColorFilter(ColorFilter colorFilter) {
        this.mDrawableProperties.setColorFilter(colorFilter);
        this.mCurrentDelegate.setColorFilter(colorFilter);
    }

    public void setDither(boolean dither) {
        this.mDrawableProperties.setDither(dither);
        this.mCurrentDelegate.setDither(dither);
    }

    public void setFilterBitmap(boolean filterBitmap) {
        this.mDrawableProperties.setFilterBitmap(filterBitmap);
        this.mCurrentDelegate.setFilterBitmap(filterBitmap);
    }

    public boolean setVisible(boolean visible, boolean restart) {
        super.setVisible(visible, restart);
        return this.mCurrentDelegate.setVisible(visible, restart);
    }

    public void unscheduleDrawable(Drawable who, Runnable what) {
        this.unscheduleSelf(what);
    }
}

